using DG.Tweening;
using System;
using UnityEngine;
using UnityEngine.UI;

namespace BToolkit.ExeUtils
{
    public class Panel : MonoBehaviour
    {
        protected string[] excludes = new string[] { "Viewport" };

        public virtual void Open(Action onAnimEnd = null)
        {
            float duration = 0.35f;
            gameObject.SetActive(true);
            ScrollRect scrollRect = GetComponentInChildren<ScrollRect>();
            if (scrollRect) scrollRect.enabled = false;
            transform.localScale = Vector3.zero;
            transform.DOScale(Vector3.one, duration).SetEase(Ease.OutExpo).OnComplete(() => {
                if (scrollRect) scrollRect.enabled = true;
                onAnimEnd?.Invoke();
            });
        }

        public virtual void Close(Action onAnimEnd = null)
        {
            float duration = 0.2f;
            transform.DOScale(Vector3.zero, duration).OnComplete(() =>
            {
                transform.localScale = Vector3.one;
                gameObject.SetActive(false);

                onAnimEnd?.Invoke();
            });
        }
    }
}